package com.qingke.memo.command.system;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.qingke.memo.command.SystemCommand;
import com.qingke.memo.pojo.Memo;
import com.qingke.memo.unit.MConsole;

public class SelectMemoByTitle extends SystemCommand {

	@Override
	public void execute() {
		String title=MConsole.promptCanEmpty("title:");
		Memo memo=new Memo();
		memo.setTitle("%"+title+"%");
		
		List<Memo> list=dao.selectMemosByTitle(memo);
		if(list.size()==0){
			MConsole.println("no result.");
			return ;
		}
		Collections.sort(list, new Comparator<Memo>(){
			@Override
			public int compare(Memo o1, Memo o2) {
				return -o1.getCreateTime().compareTo(o2.getCreateTime());
			}
		});
		MConsole.println("-------memos-------");
		for(Memo m:list){
			MConsole.println(m.toSimpleString());
		}
		MConsole.println();
	}

}
